import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Camello here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Camello extends Animal
{
    /**
     * Act - do whatever the Camello wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    
    private GreenfootImage img1, img2, img3;
    private SimpleTimer camelloTimer;
    private int velocidad;
    
    public Camello()
    {
        img1 = new GreenfootImage("c1.png");
        img2 = new GreenfootImage("c2.png");
        img3 = new GreenfootImage("c3.png");
        setImage(img1);
        camelloTimer = new SimpleTimer();
        camelloTimer.mark();
        velocidad = 1;
    }
    
    public void act() 
    {
        if(isTouching(Jugador.class) || isTouching(Obstaculo.class)){
            ((PistaAutomovil)getWorld()).addPolice();
            ((PistaAutomovil)getWorld()).removeObs(this);
        }
        else{
            if(((PistaAutomovil)getWorld()).getAdv()){
                velocidad = 5;
                ((PistaAutomovil)getWorld()).advertencia(false);
            }
        
            if(getX() >= 0){
                setLocation(getX() - velocidad, getY());
            }
            
            if(camelloTimer.millisElapsed() > 300){
                switchImage();
                camelloTimer.mark();
            }
        
            if(getX() <= getImage().getWidth()/2){
                ((PistaAutomovil)getWorld()).removeObs(this);
            }
        
        }
    }    
    
    /**Metodo para alternar las imagenes del leon
     *  y simular el movimiento.
     */
    public void switchImage()
    {
        if(getImage() == img1)
            setImage(img2);
        else
            if(getImage() == img2)
                setImage(img3);
            else
                if(getImage() == img3)
                    setImage(img1);
    } 
}
